import os

images_folder = "C:\\Users\Administrator\\Desktop\shuju\\hje\\images"
labels_folder = "C:\\Users\Administrator\\Desktop\shuju\\hje\\labels"

# existing_labels = set(os.path.splitext(file)[0] for file in os.listdir(labels_folder) if file.endswith(".txt"))

existing_images = set(os.path.splitext(file)[0] for file in os.listdir(images_folder) if file.endswith(".jpg"))
# for file in os.listdir(images_folder):
#     if file.endswith(".jpg"):
#         file_name = os.path.splitext(file)[0]
#         if file_name not in existing_labels:
#             os.remove(os.path.join(images_folder, file))
#             print(f"Deleted {file}")



for file in os.listdir(labels_folder):
    if file.endswith(".txt"):
        file_name = os.path.splitext(file)[0]
        if file_name not in existing_images:
            os.remove(os.path.join(labels_folder, file))
            print(f"Deleted {file}")